home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / LSEQ101.ZIP / LSFIRST.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  92 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lsfirst.c    1.4 - 90/06/20" */
  5.  
  6. /* ansi headers */
  7. #include <errno.h>
  8.  
  9. /* local headers */
  10. #include "lseq_.h"
  11.  
  12. /*man---------------------------------------------------------------------------
  13. NAME
  14.      lsfirst - first lseq record
  15.  
  16. SYNOPSIS
  17.      #include <lseq.h>
  18.  
  19.      int lsfirst(lsp)
  20.      lseq_t *lsp;
  21.  
  22. DESCRIPTION
  23.      The lsfirst function positions the cursor of lseq lsp on the
  24.      first record in that lseq.
  25.  
  26.      lsfirst will fail if one or more of the following is true:
  27.  
  28.      [EINVAL]       lsp is not a valid lseq pointer.
  29.      [LSELOCK]      lsp is not locked.
  30.      [LSENOPEN]     lsp is not open.
  31.      [LSENREC]      lsp is empty.
  32.  
  33. SEE ALSO
  34.      lslast, lsnext, lsprev, lsreccnt.
  35.  
  36. DIAGNOSTICS
  37.      Upon successful completion, a value of 0 is returned.  Otherwise,
  38.      a value of -1 is returned, and errno set to indicate the error.
  39.  
  40. ------------------------------------------------------------------------------*/
  41. int lsfirst(lsp)
  42. lseq_t *lsp;
  43. {
  44.     /* validate arguments */
  45.     if (!ls_valid(lsp)) {
  46.         errno = EINVAL;
  47.         return -1;
  48.     }
  49.  
  50.     /* check if not open */
  51.     if (!(lsp->flags & LSOPEN)) {
  52.         errno = LSENOPEN;
  53.         return -1;
  54.     }
  55.  
  56.     /* check locks */
  57.     if (!(lsp->flags & LSLOCKS)) {
  58.         errno = LSELOCK;
  59.         return -1;
  60.     }
  61.  
  62.     /* check if lsp is empty */
  63.     if (lsp->lshdr.reccnt == NIL) {
  64.         errno = LSENREC;
  65.         return -1;
  66.     }
  67.  
  68.     /* check if already on first record */
  69.     if (lsp->clspos == lsp->lshdr.first) {
  70.         errno = 0;
  71.         return 0;
  72.     }
  73.  
  74.     /* set cursor to first record */
  75.     lsp->clspos = lsp->lshdr.first;
  76.  
  77.     /* read in first record */
  78.     if (lsp->clspos == NIL) {
  79.         LSEPRINT;
  80.         errno = LSEPANIC;
  81.         return -1;
  82.     } else {
  83.         if (ls_rcget(lsp, lsp->clspos, lsp->clsrp) == -1) {
  84.             LSEPRINT;
  85.             return -1;
  86.         }
  87.     }
  88.  
  89.     errno = 0;
  90.     return 0;
  91. }
  92.